﻿' LibWowArmory
' by Ronald M. Clifford (roncli@roncli.com)
'
' This source code is released under the GNU Library General Public License (LGPL) Version 2.1.

Imports roncliProductions.LibWowArmory.Dungeon
Imports System
Imports System.Globalization
Imports System.Linq

Namespace roncliProductions.LibWowArmory.Item.Search

    ''' <summary>
    ''' A class that encapsulates the Armory's source filters
    ''' </summary>
    ''' <remarks></remarks>
    Public Class SourceFilter

        Friend Property Source As String = "all"
        Friend Property Dungeon As String
        Friend Property Boss As Integer
        Friend Property Difficulty As String
        Friend Property Faction As String
        Friend Property Pvp As String

        ''' <summary>
        ''' The source of the items to search for
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property SourceFilter As Enums.SourceFilterType
            Get
                Select Case Source
                    Case "dungeon"
                        Return Enums.SourceFilterType.DungeonsAndRaidDrops
                    Case "reputation"
                        Return Enums.SourceFilterType.ReputationRewards
                    Case "quest"
                        Return Enums.SourceFilterType.QuestRewards
                    Case "pvpAlliance"
                        Return Enums.SourceFilterType.PvpRewardsAlliance
                    Case "pvpHorde"
                        Return Enums.SourceFilterType.PvpRewardsHorde
                    Case Else
                        Return Enums.SourceFilterType.AllSources
                End Select
            End Get
            Set(ByVal value As Enums.SourceFilterType)
                Clear()
                Select Case value
                    Case Enums.SourceFilterType.AllSources
                        Source = "all"
                    Case Enums.SourceFilterType.DungeonsAndRaidDrops
                        Source = "dungeon"
                        Dungeon = "all"
                    Case Enums.SourceFilterType.ReputationRewards
                        Source = "reputation"
                        Faction = "-1"
                    Case Enums.SourceFilterType.QuestRewards
                        Source = "quest"
                    Case Enums.SourceFilterType.PvpRewardsAlliance
                        Source = "pvpAlliance"
                        Pvp = "all"
                    Case Enums.SourceFilterType.PvpRewardsHorde
                        Source = "pvpHorde"
                        Pvp = "all"
                End Select
            End Set
        End Property

        ''' <summary>
        ''' The dungeon to search for items in
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property DungeonFilter As String
            Get
                If Source = "dungeon" Then
                    Return Dungeon
                Else
                    Return ""
                End If
            End Get
            Set(ByVal value As String)
                Clear()
                Source = "dungeon"
                If value = "" Then
                    Dungeon = "all"
                Else
                    Dungeon = value
                End If
                Difficulty = "all"
            End Set
        End Property

        ''' <summary>
        ''' The type of dungeon to search for items in
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property DungeonType As Enums.DungeonType
            Get
                If Source = "dungeon" Then
                    Select Case Dungeon
                        Case "dungeons"
                            Return Enums.DungeonType.DungeonsOnly
                        Case "raids"
                            Return Enums.DungeonType.RaidsOnly
                        Case "badgeofjustice"
                            Return Enums.DungeonType.BadgeOfJusticeRewards
                        Case "emblemofheroism"
                            Return Enums.DungeonType.EmblemOfHeroism
                        Case "emblemofvalor"
                            Return Enums.DungeonType.EmblemOfValor
                        Case "emblemofconquest"
                            Return Enums.DungeonType.EmblemOfConquest
                        Case Else
                            Return Enums.DungeonType.AllDungeonsAndRaids
                    End Select
                Else
                    Return Enums.DungeonType.AllDungeonsAndRaids
                End If
            End Get
            Set(ByVal value As Enums.DungeonType)
                Clear()
                Source = "dungeon"
                Select Case value
                    Case Enums.DungeonType.AllDungeonsAndRaids
                        Dungeon = "all"
                    Case Enums.DungeonType.DungeonsOnly
                        Dungeon = "dungeons"
                    Case Enums.DungeonType.RaidsOnly
                        Dungeon = "raids"
                    Case Enums.DungeonType.BadgeOfJusticeRewards
                        Dungeon = "badgeofjustice"
                    Case Enums.DungeonType.EmblemOfHeroism
                        Dungeon = "emblemofheroism"
                    Case Enums.DungeonType.EmblemOfValor
                        Dungeon = "emblemofvalor"
                    Case Enums.DungeonType.EmblemOfConquest
                        Dungeon = "emblemofconquest"
                End Select
                Difficulty = "all"
            End Set
        End Property

        ''' <summary>
        ''' The boss to search for item drops from
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property BossFilter As Integer
            Get
                Return Boss
            End Get
            Set(ByVal value As Integer)
                Dim strDungeon As String = Dungeon
                Clear()
                Dungeon = strDungeon
                Source = "dungeon"
                Boss = value
                Difficulty = "all"
            End Set
        End Property

        ''' <summary>
        ''' The difficulty type of the dungeon to search for item drops from
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property DifficultyFilter As Enums.DifficultyType
            Get
                Select Case Difficulty
                    Case "normal"
                        Return Enums.DifficultyType.NormalOnly
                    Case "heroic"
                        Return Enums.DifficultyType.HeroicOnly
                    Case Else
                        Return Enums.DifficultyType.NormalAndHeroic
                End Select
            End Get
            Set(ByVal value As Enums.DifficultyType)
                If Source <> "dungeon" Then
                    Throw New InvalidOperationException("The Difficulty filter is only valid for dungeons or raids.")
                    Exit Property
                End If
                If Dungeon <> "dungeons" And Dungeon <> "raids" Then
                    Dim dDungeons As New Dungeons
                    Dim varDungeon = (From d In dDungeons.Dungeons Where d.Key = Dungeon)
                    If varDungeon.Count = 0 Then
                        Throw New InvalidOperationException("Heroic difficulty is not available for this dungeon or raid.")
                        Exit Property
                    End If
                    If Not varDungeon.First.HasHeroic Then
                        Throw New InvalidOperationException("Heroic difficulty is not available for this dungeon or raid.")
                        Exit Property
                    End If
                End If
                Select Case value
                    Case Enums.DifficultyType.NormalAndHeroic
                        Difficulty = "all"
                    Case Enums.DifficultyType.NormalOnly
                        Difficulty = "normal"
                    Case Enums.DifficultyType.HeroicOnly
                        Difficulty = "heroic"
                End Select
            End Set
        End Property

        ''' <summary>
        ''' The faction to search for items in
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property FactionFilter As Integer
            Get
                Dim intFaction As Integer
                If Source = "reputation" And Integer.TryParse(Faction, intFaction) Then
                    Return intFaction
                Else
                    Return 0
                End If
            End Get
            Set(ByVal value As Integer)
                Clear()
                Source = "reputation"
                If value = 0 Then
                    Faction = "-1"
                Else
                    Faction = value.ToString(CultureInfo.InvariantCulture)
                End If
            End Set
        End Property

        ''' <summary>
        ''' The type of PvP Alliance items to look for
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property PvpAllianceFilter As Enums.PvpAllianceSourceType
            Get
                If Source = "pvpAlliance" Then
                    Select Case Pvp
                        Case "wintergrasp"
                            Return Enums.PvpAllianceSourceType.Wintergrasp
                        Case "arena6"
                            Return Enums.PvpAllianceSourceType.ArenaSeason6
                        Case "arena5"
                            Return Enums.PvpAllianceSourceType.ArenaSeason5
                        Case "arena4"
                            Return Enums.PvpAllianceSourceType.ArenaSeason4
                        Case "honor"
                            Return Enums.PvpAllianceSourceType.HonorRewards
                        Case "ab"
                            Return Enums.PvpAllianceSourceType.ArathiBasin
                        Case "av"
                            Return Enums.PvpAllianceSourceType.AlteracVally
                        Case "wsg"
                            Return Enums.PvpAllianceSourceType.WarsongGulch
                        Case "halaa"
                            Return Enums.PvpAllianceSourceType.Halaa
                        Case "honorhold"
                            Return Enums.PvpAllianceSourceType.HonorHold
                        Case "terrokar" 'Incorrect spelling is intentional, this is how the Armory has it spelled.
                            Return Enums.PvpAllianceSourceType.Terokkar
                        Case "zangarmarsh"
                            Return Enums.PvpAllianceSourceType.Zangarmarsh
                        Case Else
                            Return Enums.PvpAllianceSourceType.AllPvpSources
                    End Select
                Else
                    Return Enums.PvpAllianceSourceType.AllPvpSources
                End If
            End Get
            Set(ByVal value As Enums.PvpAllianceSourceType)
                Clear()
                Source = "pvpAlliance"
                Select Case value
                    Case Enums.PvpAllianceSourceType.AllPvpSources
                        Pvp = "all"
                    Case Enums.PvpAllianceSourceType.Wintergrasp
                        Pvp = "wintergrasp"
                    Case Enums.PvpAllianceSourceType.ArenaSeason6
                        Pvp = "arena6"
                    Case Enums.PvpAllianceSourceType.ArenaSeason5
                        Pvp = "arena5"
                    Case Enums.PvpAllianceSourceType.ArenaSeason4
                        Pvp = "arena4"
                    Case Enums.PvpAllianceSourceType.HonorRewards
                        Pvp = "honor"
                    Case Enums.PvpAllianceSourceType.ArathiBasin
                        Pvp = "ab"
                    Case Enums.PvpAllianceSourceType.AlteracVally
                        Pvp = "av"
                    Case Enums.PvpAllianceSourceType.WarsongGulch
                        Pvp = "wsg"
                    Case Enums.PvpAllianceSourceType.Halaa
                        Pvp = "halaa"
                    Case Enums.PvpAllianceSourceType.HonorHold
                        Pvp = "honorhold"
                    Case Enums.PvpAllianceSourceType.Terokkar
                        Pvp = "terrokar" 'Incorrect spelling is intentional, this is how the Armory has it spelled.
                    Case Enums.PvpAllianceSourceType.Zangarmarsh
                        Pvp = "zangarmarsh"
                End Select
            End Set
        End Property

        ''' <summary>
        ''' The type of PvP Horde items to look for
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property PvpHordeFilter As Enums.PvpHordeSourceType
            Get
                If Source = "pvpHorde" Then
                    Select Case Pvp
                        Case "wintergrasp"
                            Return Enums.PvpHordeSourceType.Wintergrasp
                        Case "arena6"
                            Return Enums.PvpHordeSourceType.ArenaSeason6
                        Case "arena5"
                            Return Enums.PvpHordeSourceType.ArenaSeason5
                        Case "arena4"
                            Return Enums.PvpHordeSourceType.ArenaSeason4
                        Case "honor"
                            Return Enums.PvpHordeSourceType.HonorRewards
                        Case "ab"
                            Return Enums.PvpHordeSourceType.ArathiBasin
                        Case "av"
                            Return Enums.PvpHordeSourceType.AlteracVally
                        Case "wsg"
                            Return Enums.PvpHordeSourceType.WarsongGulch
                        Case "halaa"
                            Return Enums.PvpHordeSourceType.Halaa
                        Case "thrallmar"
                            Return Enums.PvpHordeSourceType.Thrallmar
                        Case "terrokar" 'Incorrect spelling is intentional, this is how the Armory has it spelled.
                            Return Enums.PvpHordeSourceType.Terokkar
                        Case "zangarmarsh"
                            Return Enums.PvpHordeSourceType.Zangarmarsh
                        Case Else
                            Return Enums.PvpHordeSourceType.AllPvpSources
                    End Select
                Else
                    Return Enums.PvpHordeSourceType.AllPvpSources
                End If
            End Get
            Set(ByVal value As Enums.PvpHordeSourceType)
                Clear()
                Source = "pvpHorde"
                Select Case value
                    Case Enums.PvpHordeSourceType.AllPvpSources
                        Pvp = "all"
                    Case Enums.PvpHordeSourceType.Wintergrasp
                        Pvp = "wintergrasp"
                    Case Enums.PvpHordeSourceType.ArenaSeason6
                        Pvp = "arena6"
                    Case Enums.PvpHordeSourceType.ArenaSeason5
                        Pvp = "arena5"
                    Case Enums.PvpHordeSourceType.ArenaSeason4
                        Pvp = "arena4"
                    Case Enums.PvpHordeSourceType.HonorRewards
                        Pvp = "honor"
                    Case Enums.PvpHordeSourceType.ArathiBasin
                        Pvp = "ab"
                    Case Enums.PvpHordeSourceType.AlteracVally
                        Pvp = "av"
                    Case Enums.PvpHordeSourceType.WarsongGulch
                        Pvp = "wsg"
                    Case Enums.PvpHordeSourceType.Halaa
                        Pvp = "halaa"
                    Case Enums.PvpHordeSourceType.Thrallmar
                        Pvp = "thrallmar"
                    Case Enums.PvpHordeSourceType.Terokkar
                        Pvp = "terrokar" 'Incorrect spelling is intentional, this is how the Armory has it spelled.
                    Case Enums.PvpHordeSourceType.Zangarmarsh
                        Pvp = "zangarmarsh"
                End Select
            End Set
        End Property

        ''' <summary>
        ''' A function that clears the current filter
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub Clear()
            Source = "all"
            Dungeon = ""
            Boss = 0
            Difficulty = ""
            Faction = ""
            Pvp = ""
        End Sub

    End Class

End Namespace
